package com.cjm.one.model.custom.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cjm.one.model.base.BaseEntity;
import com.cjm.one.model.custom.enums.LoginType;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Objects;

/**
 * 客户表
 * @TableName customer_info
 */
@TableName(value ="customer_info")
@Data
public class CustomerInfo  extends BaseEntity  {

    /**
     * 微信openId
     */
    private String wxOpenId;

    /**
     * 客户昵称
     */
    private String nickname;

    /**
     * 性别
     */
    private String gender;

    /**
     * 头像
     */
    private String avatarUrl;

    /**
     * 电话
     */
    private String phone;

    /**
     * 1有效，2禁用
     */
    private Integer status;

//    /**
//     * 创建时间
//     */
    private LocalDateTime createTime;
//
//    /**
//     *
//     */
//    private LocalDateTime updateTime;

    /**
     * 删除标识 1删除 0未删除
     */
//    private Integer isDeleted;

    /**
     * 预留
     */
    private Integer userType;

    /**
     * 用户等级
     */
    private Integer userGrade;

    /**
     * 用户经验
     */
    private Long userLesson;

    private String email;
    private String password;

    private String salt;

    private String payPassword;

    private String paySalt;

    private String birthday;

    private BigDecimal balance;

    public String getIdentifier(LoginType type) {
        return switch(type) {
            case PHONE -> this.phone;
            case EMAIL -> this.email;
        };
    }


    @TableField(exist = false)
    private static final long serialVersionUID = 1L;


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof CustomerInfo that)) return false;
        if (!super.equals(o)) return false;
        return Objects.equals(getWxOpenId(), that.getWxOpenId()) && Objects.equals(getNickname(), that.getNickname()) && Objects.equals(getGender(), that.getGender()) && Objects.equals(getAvatarUrl(), that.getAvatarUrl()) && Objects.equals(getPhone(), that.getPhone()) && Objects.equals(getStatus(), that.getStatus()) && Objects.equals(getCreateTime(), that.getCreateTime()) && Objects.equals(getUserType(), that.getUserType()) && Objects.equals(getUserGrade(), that.getUserGrade()) && Objects.equals(getUserLesson(), that.getUserLesson()) && Objects.equals(getEmail(), that.getEmail()) && Objects.equals(getPassword(), that.getPassword()) && Objects.equals(getSalt(), that.getSalt()) && Objects.equals(getPayPassword(), that.getPayPassword()) && Objects.equals(getPaySalt(), that.getPaySalt()) && Objects.equals(getBirthday(), that.getBirthday()) && Objects.equals(getBalance(), that.getBalance());
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), getWxOpenId(), getNickname(), getGender(), getAvatarUrl(), getPhone(), getStatus(), getCreateTime(), getUserType(), getUserGrade(), getUserLesson(), getEmail(), getPassword(), getSalt(), getPayPassword(), getPaySalt(), getBirthday(), getBalance());
    }

    @Override
    public String toString() {
        return "CustomerInfo{" +
                "wxOpenId='" + wxOpenId + '\'' +
                ", nickname='" + nickname + '\'' +
                ", gender='" + gender + '\'' +
                ", avatarUrl='" + avatarUrl + '\'' +
                ", phone='" + phone + '\'' +
                ", status=" + status +
                ", createTime=" + createTime +
                ", userType=" + userType +
                ", userGrade=" + userGrade +
                ", userLesson=" + userLesson +
                ", email='" + email + '\'' +
                ", password='" + password + '\'' +
                ", salt='" + salt + '\'' +
                ", payPassword='" + payPassword + '\'' +
                ", paySalt='" + paySalt + '\'' +
                ", birthday='" + birthday + '\'' +
                ", balance=" + balance +
                '}';
    }
}